package flashpromotionservicelogic

import (
	"context"

	"github.com/blog-zero/rpc/model/smsmodel"
	"github.com/blog-zero/rpc/sms/internal/svc"
	"github.com/blog-zero/rpc/sms/smsclient"

	"github.com/zeromicro/go-zero/core/logx"
)

type FlashPromotionUpdateStatusLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewFlashPromotionUpdateStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FlashPromotionUpdateStatusLogic {
	return &FlashPromotionUpdateStatusLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *FlashPromotionUpdateStatusLogic) FlashPromotionUpdateStatus(in *smsclient.FlashPromotionUpdateStatusReq) (*smsclient.FlashPromotionUpdateStatusResp, error) {
	item, _ := l.svcCtx.SmsFlashPromotionModel.FindOne(l.ctx, in.Id)

	err := l.svcCtx.SmsFlashPromotionModel.Update(l.ctx, &smsmodel.SmsFlashPromotion{
		Id:        in.Id,
		Title:     item.Title,
		StartDate: item.StartDate,
		EndDate:   item.EndDate,
		Status:    in.Status,
	})
	if err != nil {
		return nil, err
	}

	return &smsclient.FlashPromotionUpdateStatusResp{}, nil
}
